package com.example.campus_order_sb.controller;

import com.example.campus_order_sb.dto.MenuResponse;
import com.example.campus_order_sb.entity.Category;
import com.example.campus_order_sb.entity.Food;
import com.example.campus_order_sb.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

@RestController
@RequestMapping("/api")
public class MenuController {

    @Autowired
    private MenuService menuService;

    @GetMapping("/menu")
    public ResponseEntity<MenuResponse> getMenu() {
        try {
            List<Category> categories = menuService.getAllCategories();
            List<Food> foods = menuService.getAllFoods();

            MenuResponse response = new MenuResponse(categories, foods);
            return ResponseEntity.ok(response);
        } catch (Exception e) {
            return ResponseEntity.ok(new MenuResponse("获取菜单失败: " + e.getMessage()));
        }
    }
}